package com.zhanggm.s3.starter.fileupload.service;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;


public class FileService {

    public FileService() {
        System.out.println("fileService 初始化完成，可以调用了");
    }

    public String upload(MultipartFile file) throws IOException {
        String fileName = UUID.randomUUID().toString();
        String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        file.transferTo(new File("/home/file/"+fileName+extName));
        return fileName+extName;
    }


}
